package com.sgb.kjwl.viewmodel.home;

import com.sgb.kjwl.api.APIManager;
import com.swgk.core.view.entity.ChannelEntity;
import com.sgb.kjwl.repository.HomeRepertory;
import com.sgb.kjwl.view.ui.activity.PreferredChoiceActivity;
import com.swgk.core.mmkvutil.CacheMarker;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelperNew;
import com.swgk.core.mmkvutil.MkvUtils;
import com.swgk.core.mmkvutil.DatalUtils;

import java.util.ArrayList;
import java.util.List;

public class PreferredChoiceModel extends BaseViewModel {
    private HomeRepertory repertory;
    private PreferredChoiceActivity activity;
    private ArrayList<String> list = new ArrayList<String>();

    public PreferredChoiceModel(PreferredChoiceActivity activity, HomeRepertory repertory) {
        this.activity = activity;
        this.repertory = repertory;
    }

    /**
     * 通过联网获取首页栏目
     */
    public void getChannelData() {
        DialogHelperNew.showProgressDialog(activity, "数据加载中...").setCanceledOnTouchOutside(false);
        APIManager.getInstance().getCommonAPI().getChannelList().enqueue(new ICallBack<BaseEntity<List<ChannelEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<ChannelEntity>> data) {
                DialogHelperNew.dismissProgressDialog();
                List<ChannelEntity> channelEntityList = new ArrayList<>();
                channelEntityList.addAll(data.getData());
                activity.getData(channelEntityList);
                DatalUtils.getInstance().putData(MkvUtils.CommomData, CacheMarker.SysHomePageTitle, data.getData());
            }
        });
    }
}
